﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using PlanningGIS.Framework;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;

namespace PlanningGIS.TocContextMenu
{
    /// <summary>
    /// 
    /// </summary>
    public  class RemoveJoins:BaseCommand 
    {
        /// <summary>
        /// 
        /// </summary>
        IApplication m_Application = null;
        /// <summary>
        /// 
        /// </summary>
        public RemoveJoins()
        {
            base.m_caption = "移除所有关联";
            base.m_toolTip = base.Caption;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="hook"></param>
        public override void OnCreate(object hook)
        {
            if (m_Application == null)
            {
                m_Application = hook as IApplication;
            }            
        }
        
        /// <summary>
        /// 
        /// </summary>
        public override void OnClick()
        {
            IDisplayRelationshipClass pDIsRelClass = (m_Application as IFramework).TOCControl.CustomProperty as IDisplayRelationshipClass;
            pDIsRelClass.DisplayRelationshipClass(null, esriJoinType.esriLeftOuterJoin);
        }

        /// <summary>
        /// 
        /// </summary>
        public override bool Enabled
        {
            get
            {
                IDisplayRelationshipClass pDIsRelClass = (m_Application as IFramework).TOCControl.CustomProperty as IDisplayRelationshipClass;
                if (pDIsRelClass != null && pDIsRelClass.RelationshipClass != null)
                {
                    return true;
                }
                return false;
            }
        }
        
    }
    
}
